package com.market.common.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@AllArgsConstructor
public class ResponseResult<T> {
    private String msg;
    private int status;
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return success(ResponseCode.SUCCESS, data);
    }

    public static <T> ResponseResult<T> success(ResponseCode code, T data) {
        return new ResponseResultBuilder<T>()
                .msg(code.getMsg())
                .status(code.getStatus())
                .data(data)
                .build();
    }


    public static <T> ResponseResult<T> error() {
        return error(ResponseCode.ERROR);
    }

    public static <T> ResponseResult<T> error(ResponseCode code) {
        return error(code, null);
    }

    public static <T> ResponseResult<T> error(ResponseCode code, T data) {
        return new ResponseResultBuilder<T>()
                .msg(code.getMsg())
                .status(code.getStatus())
                .data(data)
                .build();
    }
}
